#-*-coding:utf8-*-
from django.http import HttpResponse
from Model.models import Shop,TicketType
import json
def shop_detail(request):
    '''
    @author xjx
    @email arthursnoopyxu@foxmail.com
    @date 2017-9-23 18:42
    商家信息票类信息，所有商家信息，票类简介，票类名称，|| 单个票类 票类id 数量||订单数组所有信息 ||注意电子码    
    '''

    if request.method == 'GET':
        requestValue = request.GET['shopId']
        shopInfo = []
        shop=Shop.objects.get(id=requestValue)
        shopId=shop.id
        shopAvatar = shop.avatar
        shopPic = shop.shop_pic
        shopName = shop.shop_name
        shopArea = shop.area
        shopAddress = shop.detail_address
        price = shop.price
        shopPrice = shop.original_price
        html=shop.html
        shopInfo.append({'shopId':shopId,'shopAvatar':shopAvatar,
	'shopName':shopName,'shopAddress':shopAddress,
        'price':price,'shopPic':shopPic,
        'shopPrice':shopPrice,'html':html,
        })
        
        ticketTypes = []
        tickets=TicketType.objects.filter(id=requestValue)
        for ticket in tickets:
            ticketKindId = ticket.id
            ticketKindName = ticket.ticket_name
            ticketKindOriginalPrice = ticket.original_price
            ticketKindPrice = ticket.price
            ticketTypeName = ticket.ticket_type
            ticketKindInfo = ticket.comment
            ticketKindEffectiveTime = str(ticket.effective_time)
            ticketKindAvatar = ticket.avatar
            ticketKindFailBit = ticket.fail_bit
            ticketTypes.append({'ticketKindId':ticketKindId,'ticketKindName':ticketKindName,'ticketKindOriginalPrice':ticketKindOriginalPrice,
        'ticketKindPrice':ticketKindPrice,'ticketTypeName':ticketTypeName,
        'ticketKindInfo':ticketKindInfo,'ticketKindEffectiveTime':ticketKindEffectiveTime,
        'ticketKindAvatar':ticketKindAvatar,'ticketKindFailBit':ticketKindFailBit,
        })


        shopDetail={'shopInfo':shopInfo,'ticketTypes':ticketTypes}
        return HttpResponse(json.dumps(shopDetail, ensure_ascii=False), content_type="application/json;charset=utf8")
    else:
        return HttpResponse(json.dumps({'error':404}, ensure_ascii=False), content_type="application/json;charset=utf8")
